﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HerGoS.WebControlExtend;
using HerGoS.ControlsUI;
using HerGoS.Viaticos.Engine;

namespace HerGoS.WebUI.Viaticos.CocienteKmPrecio
{
    public partial class CocienteKmPrecio_Listado :  PageBase
    {
        
        #region Propiedades
        public List<HerGoS.Viaticos.Entities.TarifaKmRecorridos> TarifasKmRecorridos
        {
            get
            {
                if (ViewState["TarifasKmRecorridos"] != null)
                    return (List<HerGoS.Viaticos.Entities.TarifaKmRecorridos>)ViewState["TarifasKmRecorridos"];
                return null;
            }
            set
            {
                ViewState["TarifasKmRecorridos"] = value;
            }

        }
        #endregion
     
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Initialize();
                LoadGridCociente(false);
            }
        }

        void Initialize()
        {
            this.GridCociente.Settings(new GridViewExtBasic());
            this.btnNuevo.Settings(new ButtonExtText());
            this.btnRefresh.Settings(new ButtonExtText());
        }
        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            LoadGridCociente(false);
        }




        private void LoadGridCociente(bool cache)
        {
            if (!cache)
                TarifasKmRecorridos = GestorTarifaKmRecorridos.Consultar();

            this.GridCociente.DataSource = TarifasKmRecorridos;
            this.GridCociente.DataBind();
        }

        protected void GridCociente_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ImageButtonExt Editar = e.Row.FindControl("btnEditar") as ImageButtonExt;
                if (Editar != null)
                {
                    Editar.Settings(new ImageButtonExtEdit());
                    int oid = DataBinder.Eval(e.Row.DataItem, "OID").ToInteger();
                    Editar.OnClientClick = "Editar(" + oid.ToString() + "); return false;";
                }

              
            }
        }

        protected void GridCociente_PageIndexChanging(Object sender, GridViewPageEventArgs e)
        {
            GridCociente.PageIndex = e.NewPageIndex;
            LoadGridCociente(true);
        }

      
    }
}